<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Markdown; 
class BlogController extends Controller
{
    /**
     * 
     * 显示界面
     * 
     */
    public function getIndex()
    {
        $data = \DB::table('blog')->paginate(3);


        return view('blog.index',['data'=>$data]);
    }

    /**
     * 
     * 添加界面
     * 
     */
    public function getAdd()
    {
        return view('blog.mk_add');
    }

    public function postYl(Request $request)
    {
        return Markdown::convertToHtml($request->cont);    
    }

    /**
     * 
     * 执行添加
     * 
     *
     */
    public function postIns(Request $request)
    {
        $data = $request -> except(['_token']);
        // dd($data);
        $res = \DB::table('blog')->insert($data);
        return redirect('/blog');

    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function getShow($id)
    {
        $data = \DB::table('blog')->where('id',$id)->first();

        Markdown::convertToHtml($data->content);    

        return view('blog.show',['data'=>$data]);
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function getDel($id)
    {
        \DB::table('blog')->where('id',$id)->delete();
        return redirect('/blog');
        // echo $id;
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
